#!/bin/bash
#2017年8月18日21:32:13
#auto create vsftpd for virtual user
#by author www.jfedu.net
########################
yum install vsftpd* db4* -y
cat>/etc/vsftpd/ftpusers.txt<<EOF
jfedu001
123456
jfedu002
123456
EOF
db_load -T -t hash -f /etc/vsftpd/ftpusers.txt /etc/vsftpd/vsftpd_login.db
chmod 700 /etc/vsftpd/ftpusers.txt
chmod 700 /etc/vsftpd/vsftpd_login.db

cat>/etc/pam.d/vsftpd<<EOF
auth    sufficient      /lib64/security/pam_userdb.so      db=/etc/vsftpd/vsftpd_login
account sufficient      /lib64/security/pam_userdb.so      db=/etc/vsftpd/vsftpd_login
EOF
useradd -s /sbin/nologin ftpuser
cat>>/etc/vsftpd/vsftpd.conf<<EOF
guest_enable=YES
guest_username=ftpuser
pam_service_name=vsftpd
user_config_dir=/etc/vsftpd/vsftpd_user_conf
virtual_use_local_privs=YES
EOF

mkdir -p /etc/vsftpd/vsftpd_user_conf/
cat>/etc/vsftpd/vsftpd_user_conf/jfedu001 <<EOF
local_root=/home/ftpuser/jfedu001
write_enable=YES
anon_world_readable_only=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
EOF
mkdir -p /home/ftpuser/jfedu001/
chown -R ftpuser.ftpuser /home/ftpuser
service vsftpd restart
